package com.zhxy.utils;

import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ResponseUtils {

    /**
     * 使用Response把结果提交到前端
     * @param response
     * @param result
     */
    public static void write(HttpServletResponse response,String result) {
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter writer=null;

        try {
            writer=response.getWriter();
            writer.write(result);
            writer.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if (writer!=null){
                writer.close();
            }
        }
    }
}
